package bloomersseeds2340

class UserController {
    
    //def scaffold = true

    def index() {}
  
 
    /*
    def beforeInterceptor = [action:this.&auth, 
           except:['doLogin', 'logout']]
   /*    
   def auth() { 
    if( !(session?.user?.role == "admin")){
      flash.message = "You must be an administrator to perform that task."
      redirect(action:"index")
      return false
     }
   }
  */
    def doLogin = {
        def user = User.findByEmailAndPassword(params.email, params.password)
        session.user = user
 
    if( !(session?.user?.role == "admin")){
      flash.message = "You must be an administrator to perform that task."
      redirect(action:"index")
      return false
     }
    if(user){
    session.user = user
    flash.message = "Hello ${user.email}!"
        redirect (controller:'UserHome', action:"userHome")
     
    }    
    else{
        flash.message= "User not found. Please try again"
        redirect (action: "index") 
    }
    def logout = {
    flash.message = "Goodbye ${session.name}"
    session.user = null
    redirect(controller:"UserHome")      
  }  
    }
    

}